package com.mingmen.supplier.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.mingmen.supplier.R;
import com.mingmen.supplier.defineview.GlideRoundTransform;
import com.mingmen.supplier.httpconfig.AppConfig;
import com.mingmen.supplier.model.RestaurantModel;

import java.util.ArrayList;
import java.util.List;


public class RestaurantListTwoAdapter extends RecyclerView.Adapter<RestaurantListTwoAdapter.ViewHolder> {
    List<RestaurantModel.DataBean> myLiveList = new ArrayList<>();
    Context mContext;
    private OnItemClickListener mOnItemClickListener;
    private int checkedPosition = -1;

    //recycleview标签
    public void setCheckedPosition(int checkedPosition) {
        this.checkedPosition = checkedPosition;
        notifyDataSetChanged();
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClickListener(View view, int pos, List<RestaurantModel.DataBean> myLiveList);
    }

    int flag = 0;

    public RestaurantListTwoAdapter(Context context, List<RestaurantModel.DataBean> myLiveList) {
        this.mContext = context;
        this.myLiveList = myLiveList;

    }

    public void setlayout(int flag) {
        this.flag = flag;
        notifyDataSetChanged();
    }

    public void setDataList(List<RestaurantModel.DataBean> list) {
        myLiveList = list;

        notifyDataSetChanged();
    }

    @Override
    public int getItemViewType(int position) {
        return super.getItemViewType(position);
    }

    View view;

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

       /* if (viewType==0){
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_restaurantlist1, parent, false);
        }else if (viewType==1){
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_restaurantlist, parent, false);
        }
*/
        view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_restaurantlisttwo, parent, false);

        ViewHolder holder = new ViewHolder(view);
        return holder;


    }


    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        holder.commodityName.setText(myLiveList.get(position).getRestaurantName());
        RestaurantModel.DataBean dataBean = myLiveList.get(position);
        Glide.with(mContext).load(AppConfig.IMGURL + dataBean.getPicture()).dontAnimate().placeholder(R.mipmap.zhanwei).error(R.mipmap.zhanwei).transform(new GlideRoundTransform(mContext, 5)).into(holder.ivAvatar);
        holder.billCount.setText("订单数 "+dataBean.getBillCount() + "");
        holder.startDate1.setText(dataBean.getEndDate());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemClickListener.onItemClickListener(v, position, myLiveList);
            }
        });
        holder.text_history.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemClickListener.onItemClickListener(v, position, myLiveList);
            }
        });
        holder.startDate.setText(dataBean.getStartDate());
    }

    @Override
    public int getItemCount() {
        return myLiveList.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        TextView commodityName;
        LinearLayout content;
        TextView text_history;
        ImageView ivAvatar;
        TextView billCount;
        TextView startDate;
        TextView startDate1;

        public ViewHolder(View itemView) {
            super(itemView);

            commodityName = (TextView) itemView.findViewById(R.id.commodityName);
            content = itemView.findViewById(R.id.content);
            text_history = itemView.findViewById(R.id.text_history);
            ivAvatar = itemView.findViewById(R.id.ivAvatar);
            billCount = itemView.findViewById(R.id.billCount);
            startDate = itemView.findViewById(R.id.startDate);
            startDate1 = itemView.findViewById(R.id.startDate1);
        }
    }


}
